
#include "Textures.h"

bool Textures::init()
{
	if (!LearnShader::init())	return false;
	std::cout << getChapterName().c_str() << "::" << getNodeName().c_str() << "::init" << std::endl;

	m_pProgram = createProgramWithDefaultPath();
	m_pContainer = ShaderTexture::create(Res_Image_Container);
	m_pAwesomeface = ShaderTexture::create(Res_Image_Awesomeface);

	CREATE_SHADER_ELEMENT_DATA(pElementData, Dataset_Indices_Rectangle);

	CREATE_SHADER_VERTEX_DATA(pVertexData, Dataset_Vertices_Rectangle_Color_Coord);
	pVertexData->setVertexSize(8);
	pVertexData->pushVertexAttrib(3, 0);
	pVertexData->pushVertexAttrib(3, 3);
	pVertexData->pushVertexAttrib(2, 6);
	m_pVertex = ShaderElementBuffer::create(pElementData, pVertexData);

	return true;
}

void Textures::release()
{

}

void Textures::update(float dt)
{
	glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	m_pProgram->use();

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, m_pContainer->getTexture());
	glUniform1i(glGetUniformLocation(m_pProgram->getProgram(), "ourTexture1"), 0);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, m_pAwesomeface->getTexture());
	glUniform1i(glGetUniformLocation(m_pProgram->getProgram(), "ourTexture2"), 1);

	m_pVertex->bindingVertexArray();
	m_pVertex->draw(6);
	m_pVertex->cleanVertexArray();
	bindTexture(nullptr);
	swapBuffers();
}
